package cn.com.wdjedu.androidapp.wjeduandroid.mvp;

import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

import cn.com.wdjedu.androidapp.wjeduandroid.db.WJEdudb;
import cn.com.wdjedu.androidapp.wjeduandroid.support.lib.mvputils.BasePresenter;
import cn.com.wdjedu.androidapp.wjeduandroid.ui.BaseActivity;
import cn.com.wdjedu.androidapp.wjeduandroid.ui.baseui.ActionBarActivity;
import nl.nl2312.rxcupboard.RxCupboard;
import nl.nl2312.rxcupboard.RxDatabase;

/**
 * Created by samson on 26/11/2016.
 */

public abstract class MvpActivity<P extends BasePresenter> extends ActionBarActivity {
    protected P mvpPresenter;
    private SQLiteDatabase db ;
    public RxDatabase rxCupboard ;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        this.mvpPresenter = createPresenter();
        if (db==null)
            db = WJEdudb.getConnection(this);
        if (rxCupboard==null)
            rxCupboard = RxCupboard.withDefault(db);
        super.onCreate(savedInstanceState);
    }

    protected abstract P createPresenter();

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mvpPresenter != null){
            mvpPresenter.dettach();
        }
    }
}
